//
//  NoticeModelTests.m
//  JKOCRealmTests
//
//  Created by 王冲 on 2019/2/27.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "NotificationModel.h"
#import <Realm/Realm.h>
@interface NoticeModelTests : XCTestCase

@property (nonatomic, strong) RLMNotificationToken *token;
    
@property (nonatomic, strong) RLMNotificationToken *token2;
    
@end

@implementation NoticeModelTests

- (void)setUp {
    
    // RLMRealm *realm = [RLMRealm defaultRealm];
    // 创建通知
//    self.token = [realm addNotificationBlock:^(RLMNotification  _Nonnull notification, RLMRealm * _Nonnull realm) {
//
//        NSLog(@"监听到修改通知");
//    }];
    
    RLMResults *results = [NotificationModel allObjects];
    self.token2 = [results addNotificationBlock:^(RLMResults * _Nullable results, RLMCollectionChange * _Nullable change, NSError * _Nullable error) {
        
        NSLog(@"%@--%@--%@", results, change, error);
        
    }];
    
    
}

- (void)tearDown {
    
    // 销毁通知
    // [self.token invalidate];
     [self.token2 invalidate];
}

- (void)testExample1 {
    
    NotificationModel *model = [[NotificationModel alloc]init];
    model.number = 2;
    model.name = @"测试2";
    
    RLMRealm *realm = [RLMRealm defaultRealm];
    
    [realm transactionWithBlock:^{
        [realm addObject:model];
    }];
    
    [realm transactionWithBlock:^{
        [realm deleteObject:model];
    }];
    
    NotificationModel *model2 = [[NotificationModel alloc]init];
    model2.number = 3;
    model2.name = @"测试3";
    
    [realm transactionWithBlock:^{
        [realm addObject:model2];
    }];
    
}



@end
